// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "LogEntry.hpp"
#include <stdlib.h>

using namespace ninf::client;

LogEntry :: LogEntry(): message(NULL){}

LogEntry :: LogEntry(const LogEntry & entry){
  message = strdup(entry.message);
  statusCode = entry.statusCode;
  jobId0     = entry.jobId0;
  jobId1     = entry.jobId1;
  jobId2     = entry.jobId2;
  time       = entry.time;
}

LogEntry :: ~LogEntry(){
  if (message != NULL)
    free(message);
}

void
LogEntry :: setMessage(char * message){
  this->message = strdup(message);
}

void
LogEntry :: setTime(char *timeStr){
  strptime(timeStr, "%m/%d %T", &time);
}

void
LogEntry :: print(FILE * fp){
  char buffer[1000];
  strftime(buffer, 1000, "%m/%d %T", &time);
  fprintf(fp, "%03d (%03d.%03d.%03d) %s, %s\n",
	  statusCode, 
	  jobId0, jobId1, jobId2, 
	  buffer, message);
}
